<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>实现列表的变换过渡效果</title>
    <script src="vue.js"></script>
    <script src="lodash.js"></script>
    <style>
      .list-item {
        display: inline-block;
        margin-right: 10px;
        background-color: red;
        border-radius: 50%;
        width: 25px;
        height: 25px;
        text-align: center;
        line-height: 25px;
        color: #fff;
      }
      /* 元素定位改变时动画 */
      .list-move {
        transition: transform 1s;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button @click="shuffle">打乱顺序</button>
      <transition-group name="list" tag="p">
        <span v-for="item in items" :key="item" class="list-item">
          {{ item }}
        </span>
      </transition-group>
    </div>
    <script>
      var vm = new Vue({
        el: "#app",
        data: {
          items: [1, 2, 3, 4, 5, 6, 7, 8, 9],
        },
        methods: {
          shuffle() {
            this.items = this.items.sort(() => {
              return Math.random() - 0.5;
            });
          },
        },
      });
    </script>
  </body>
</html>
